class Solution {
public:
    vector<int> missingTwo(vector<int>& nums)
    {
        int max = nums.size() + 2;
        int ret = 0, pos = 0, div = 0;

        for (auto num : nums) ret ^= num;
        for (int i = 1; i <= max; i++) ret ^= i;
        for (int i = 0; i < 32; i++)
        {
            if ((1 & (ret >> i)) == 1)
            {
                pos = i;
                break;
            }
        }

        for (int i = 0; i < nums.size(); i++)
        {
            if (((nums[i] >> pos) & 1) == 1)
                div ^= nums[i];
        }

        for (int i = 1; i <= max; i++)
        {
            if (((i >> pos) & 1) == 1)
                div ^= i;
        }

        return vector<int>{div, ret^ div};
    }
};

class Solution {
public:
    int missingNumber(vector<int>& nums)
    {
        int n = nums.size() + 1;
        int ret = 0;

        for (int i = 0; i < n; i++) ret ^= i;
        for (int i = 0; i < n - 1; i++) ret ^= nums[i];

        return ret;
    }
};

class Solution {
public:
    vector<int> singleNumber(vector<int>& nums)
    {
        int ret = 0, pos = 0, n = nums.size();
        for (int i = 0; i < n; i++) ret ^= nums[i];
        for (int i = 0; i < 32; i++)
        {
            if (((ret >> i) & 1) == 1)
            {
                pos = i;
                break;
            }
        }

        int num = 0;
        for (int i = 0; i < n; i++)
        {
            if (((nums[i] >> pos) & 1) == 1)
                num ^= nums[i];
        }

        return vector<int>{num, num^ ret};
    }
};